﻿using MaterialDesignThemes.Wpf;
using project.B12.IService;
using project.B12.Model.Enums;
using project.B12.Model.Models;
using software.Common.MVVM;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace project.B12.application.ViewModels.Dialogs
{
    public class AddSampleViewModel : ObservableObject
    {
        #region Service
        public IServiceDevice _serviceDevice { get; set; }

        public IMICPlateMes _mICPlateMes { get; set; }
        #endregion

        #region model
        private int _cultivateTime = 24;
        public int CultivateTime
        {
            get { return _cultivateTime; }
            set
            {
                _cultivateTime = value;
                this.RaisePropertyChanged();
            }
        }

        private List<string> sampleTypes = new List<string>();
        public List<string> SampleTypes
        {
            get { return sampleTypes; }
            set
            {
                sampleTypes = value;
                this.RaisePropertyChanged();
            }
        }

        private string sampleType;
        public string SampleType
        {
            get { return sampleType; }
            set { sampleType = value; this.RaisePropertyChanged(); }
        }

        private int sampleIndex;
        public int SampleIndex
        {
            get { return sampleIndex; }
            set { sampleIndex = value; this.RaisePropertyChanged(); }
        }
        #endregion

       

        public ObservableCollection<plateItem> Items { get; set; }

        public class plateItem
        {
            public string Name { get; set; }

            public int Count { get; set; }

            public bool IsEnabled { get; set; }
        }

        public AddSampleViewModel(IServiceDevice serviceDevice,IMICPlateMes mICPlateMes)
        {
            _serviceDevice = serviceDevice;
            _mICPlateMes = mICPlateMes;

            Init();
        }

        private void Init()
        {
            if (_mICPlateMes.microplateAntibioticConcentrationMes == null || _mICPlateMes.microplateAntibioticConcentrationMes.Count <= 0)
                return;

            Items = new ObservableCollection<plateItem>();
            for (int i = 0; i < _mICPlateMes.microplateAntibioticConcentrationMes.Count; i++)
            {
                var name = _mICPlateMes.microplateAntibioticConcentrationMes[i].name;
                sampleTypes.Add(name);

                int platCount = _serviceDevice.Items64.Where(o => o.PlateType == name && o.State == HoleState.NULL).Count();              
                if (platCount == 0)
                {
                    Items.Add(new plateItem { Name = name, Count = platCount, IsEnabled = false });
                    continue;
                }
                Items.Add(new plateItem { Name = name, Count = platCount, IsEnabled = true });
            }
            sampleIndex = 0;
        }
    }
}
